package Chapter06;

/**
 * Created by a on 2017/6/11.
 */
public class Test124 {
    public static void main(String[] args) {
        ThreadState state = new ThreadState();
        Thread thread = new Thread(state);
        System.out.println("新建线程:"+thread.getState());
        thread.start();
        System.out.println("启动线程:"+thread.getState());
        try {
            thread.sleep(100);

            System.out.println("计时等待:"+thread.getState());
            thread.sleep(1000);
            System.out.println("等待线程:"+thread.getState());
            state.notifyNow();
            System.out.println("唤醒线程:"+thread.getState());
            thread.sleep(1000);
            System.out.println("终止线程:"+thread.getState());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }


}

class ThreadState implements Runnable {

    public synchronized void waitForASecnod()throws InterruptedException {
        wait(500);
    }

    public synchronized void waitForYear() throws InterruptedException{
        wait();
    }

    public synchronized void notifyNow() throws InterruptedException {
        notify();
    }

    @Override
    public void run() {
        try {
            waitForASecnod();
            waitForYear();
        }catch (InterruptedException e){
            e.printStackTrace();
        }
    }
}

